$("h6").click(function () {
    let index = $(this).index("h6");
    $(this).addClass("active").siblings("h6").removeClass("active");
    $("form").eq(index).css("display", "block").siblings("form").css("display", "none")
})

function isUserName() {
    let reg = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
    if ($("#username" && !reg.test$($("username").val())).val() == "") {
        return false;
    }
    return true
}
function isUserPass() {
    if ($("#userpass").val() == "") {
        return false;
    }
}



$(".gotop").on("click", function () {
    $("html,body").animate({ // 让body和html回到顶部
        scrollTop: 0
    }, 500)
})

function setCookie(key, value, day) {
    let d = new Date();
    d.setDate(d.getDate() + day);
    document.cookie = key + '=' + value + ';expires=' + d;
}





let oBtnLogin = document.getElementById("btnLogin");
let oUserPass = document.getElementById("userpass");
let oUserName = document.getElementById("username");

oBtnLogin.onclick = function () {
    let xhr = new XMLHttpRequest();
    xhr.open("post", "../goodsAndShoppingCart/login.php", true);

    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            console.log(xhr.responseText);
            if (xhr.responseText.trim() == "success") {
                alert("登录成功");
                location.href = 'zy.html';
                setCookie("username", $("#username").val(), 7)
            } else {
                alert("登录失败,用户名或者密码错误");
                console.log("失败");
            }
        }
    }

    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    let str = "username=" + oUserName.value + "&userpass=" + oUserPass.value;
    xhr.send(str);
    return false;
}

